<?php
class SearchController extends Zend_Controller_Action
{	
    public function init() {
         
    }

    public function indexAction() {
       
        $key                         =  $this->_request->getParam('key',false); 
        $where = "1=1";
      
        if($key != NULL) {
            $where .= " and name LIKE '%$key%'";
        }
        
       // echo $where;die;
        $product = new Vina_Model_Products();
        $data = $product->fetchListToArray($where, 'id desc');
        $paginator         = Zend_Paginator::factory($data);
            $currentPage       = 1;
            //Check if the user is not on page 1
            $page              = $this->_getParam('page');
            if (! empty($page)) { //Where page is the current page
                $currentPage   = $this->_getParam('page');
            }
            //Set the properties for the pagination
            $paginator->setItemCountPerPage(12);
            $paginator->setPageRange(6);
            $paginator->setCurrentPageNumber($currentPage);
            Zend_Paginator::setDefaultScrollingStyle('Sliding');
            Zend_View_Helper_PaginationControl::setDefaultViewPartial('pagination.phtml');
            $paginator->setView($this->view);

            $this->view->data = $paginator;
           
    }
    public function redirectAction(){
         $key                         =  $this->_request->getParam('key',false); 
         if($key == NULL){
            $this->_redirect($_SERVER['HTTP_REFERER']);
         }else{
         $this->_redirect('/tim-kiem/'.$key);
         }
    }
    	
}
